#include "Util.h"
#include "SplitFbxByMaterial.h"
#include "SplitFbxByMaterialWithHierarchy.h"
#include <iostream>
using namespace std;
using namespace fbxTool;
#ifdef NDEBUG
int main(int argc, char** argv) {
	Util::InitConsole();
	if (argc < 4) {
		cout << "用法: " << argv[0] << " <输入FBX路径> <输出路径> <拆分数量> <是否保留层次结构(保留则设置该参数不保留不设置)>\n";
		cout << "示例1(不保留层次结构): " << argv[0] << " model.fbx output 15\n";
		cout << "示例2(保留层次结构): " << argv[0] << " model.fbx output 15 1\n";

		return -1;
	}

	string inputPath = argv[1];
	string output = argv[2];
	int splitCount = stoi(argv[3]);

	if (splitCount <= 1) {
		cerr << "无效的参数，拆分数量至少是2。\n";
		return -1;
	}

	if (!Util::CreateDirectoryIfNotExist(output)) {
		cerr << "目录操作失败，退出程序。" << endl;
		return -1;
	}

	// 使用宽字符路径加载 FBX 文件
	string wInputPath = Util::convertStringFromCurrentCodePageToUTF8(inputPath);
	string wOutputPath = Util::convertStringFromCurrentCodePageToUTF8(output);

	cout << "正在拆分文件：" << wInputPath << "\n";
	cout << "输出路径：" << wOutputPath << "\n";
	cout << "拆分数量：" << splitCount << "\n";

	SplitFbx* splitFbx;
	if (argc>4) {
		splitFbx = new SplitFbxByMaterialWithHierarchy;
	}else {
		splitFbx = new SplitFbxByMaterial;
	}
	splitFbx->process(wInputPath, wOutputPath, splitCount);

	cout << "拆分完成。\n";
	return 0;
}
#else
int main(int argc, char** argv) {
	Util::InitConsole();
	string inputPath = R"(C:\Users\ecidi-cve\Documents\WeChat Files\wxid_dxll2nrduz422\FileStorage\File\2025-04\zhuba.fbx)";
	string output = R"(D:\nginx-1.22.1\html)";
	int splitCount = 3;

	if (splitCount <= 1) {
		cerr << "无效的参数，拆分数量至少是2。\n";
		return -1;
	}

	if (!Util::CreateDirectoryIfNotExist(output)) {
		cerr << "目录操作失败，退出程序。" << endl;
		return -1;
	}

	// 使用宽字符路径加载 FBX 文件
	string wInputPath = Util::convertStringFromCurrentCodePageToUTF8(inputPath);
	string wOutputPath = Util::convertStringFromCurrentCodePageToUTF8(output);

	cout << "正在拆分文件：" << wInputPath << "\n";
	cout << "输出路径：" << wOutputPath << "\n";
	cout << "拆分数量：" << splitCount << "\n";

	// 使用宽字符路径调用拆分函数
	SplitFbx* splitFbx = new SplitFbxByMaterial;
	splitFbx->process(wInputPath, wOutputPath, splitCount);

	cout << "拆分完成。\n";
	return 0;
}
#endif
